package com.ruoyi.equipment.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.equipment.domain.EquipmentType;
import com.ruoyi.equipment.mapper.EquipmentCheckPeriodMapper;
import com.ruoyi.equipment.domain.EquipmentCheckPeriod;
import com.ruoyi.equipment.service.IEquipmentCheckPeriodService;

/**
 * 校验周期维护Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-14
 */
@Service
public class EquipmentCheckPeriodServiceImpl implements IEquipmentCheckPeriodService 
{
    @Autowired
    private EquipmentCheckPeriodMapper equipmentCheckPeriodMapper;

    /**
     * 查询校验周期维护
     * 
     * @param id 校验周期维护主键
     * @return 校验周期维护
     */
    @Override
    public EquipmentCheckPeriod selectEquipmentCheckPeriodById(Long id)
    {
        return equipmentCheckPeriodMapper.selectEquipmentCheckPeriodById(id);
    }

    /**
     * 查询校验周期维护列表
     * 
     * @param equipmentCheckPeriod 校验周期维护
     * @return 校验周期维护
     */
    @Override
    public List<EquipmentCheckPeriod> selectEquipmentCheckPeriodList(EquipmentCheckPeriod equipmentCheckPeriod)
    {
        return equipmentCheckPeriodMapper.selectEquipmentCheckPeriodList(equipmentCheckPeriod);
    }



    /**
     * 新增校验周期维护
     * 
     * @param equipmentCheckPeriod 校验周期维护
     * @return 结果
     */
    @Transactional
    @Override
    public int insertEquipmentCheckPeriod(EquipmentCheckPeriod equipmentCheckPeriod)
    {
        int rows = equipmentCheckPeriodMapper.insertEquipmentCheckPeriod(equipmentCheckPeriod);
        insertEquipmentType(equipmentCheckPeriod);
        return rows;
    }

    /**
     * 修改校验周期维护
     * 
     * @param equipmentCheckPeriod 校验周期维护
     * @return 结果
     */
    @Transactional
    @Override
    public int updateEquipmentCheckPeriod(EquipmentCheckPeriod equipmentCheckPeriod)
    {

        return equipmentCheckPeriodMapper.updateEquipmentCheckPeriod(equipmentCheckPeriod);
    }

    /**
     * 批量删除校验周期维护
     * 
     * @param ids 需要删除的校验周期维护主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEquipmentCheckPeriodByIds(Long[] ids)
    {
        equipmentCheckPeriodMapper.deleteEquipmentTypeByIds(ids);
        return equipmentCheckPeriodMapper.deleteEquipmentCheckPeriodByIds(ids);
    }

    /**
     * 删除校验周期维护信息
     * 
     * @param id 校验周期维护主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEquipmentCheckPeriodById(Long id)
    {
        equipmentCheckPeriodMapper.deleteEquipmentTypeById(id);
        return equipmentCheckPeriodMapper.deleteEquipmentCheckPeriodById(id);
    }

    /**
     * 新增${subTable.functionName}信息
     * 
     * @param equipmentCheckPeriod 校验周期维护对象
     */
    public void insertEquipmentType(EquipmentCheckPeriod equipmentCheckPeriod)
    {
        List<EquipmentType> equipmentTypeList = equipmentCheckPeriod.getEquipmentTypeList();
        Long id = equipmentCheckPeriod.getId();
        if (StringUtils.isNotNull(equipmentTypeList))
        {
            List<EquipmentType> list = new ArrayList<EquipmentType>();
            for (EquipmentType equipmentType : equipmentTypeList)
            {
                equipmentType.setId(id);
                list.add(equipmentType);
            }
            if (list.size() > 0)
            {
                equipmentCheckPeriodMapper.batchEquipmentType(list);
            }
        }
    }
}
